<template>

    <el-form :inline="true" :model="formData" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="formData.name" placeholder="请输入关键字" clearable @change="callApi" />
      </el-form-item>
  
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column fixed prop="id" label="id" width="100" />
      <el-table-column prop="name" label="职位" width="200" />
      <el-table-column prop="description" label="描述" width="200" />
      <el-table-column fixed="right" label="Operations" min-width="140">
        <template #default="scope">
          <el-button type="primary" size="small" @click="edit(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination background layout="total, prev, pager, next" :total="pageData.total" :page-size="pageData.pageSize"
      @current-change="pageChange">
    </el-pagination>
    <el-drawer v-model="drawer" title="明细" :with-header="false" size="70%">
      <!-- <el-table :data="tableData2" style="width: 100%">
        <el-table-column fixed prop="productId" label="编号" width="60"></el-table-column>
        <el-table-column fixed prop="productName" label="名称" width="120"></el-table-column>
        <el-table-column label="入库数量" width="150" prop="qty"></el-table-column>
        <el-table-column label="生产日期" width="150" prop="productionDate"></el-table-column>
        <el-table-column label="保质期" width="100" prop="shelfLife"></el-table-column>
        <el-table-column label="入库货架" width="200" >
          <template #default="scope" >
            <ShelfTree v-model="scope.row.shelfId" style="width: 100px;" disabled="true"></ShelfTree>
          </template>
        </el-table-column>
        <el-table-column label="备注" width="300" prop="brief"></el-table-column>
      </el-table> -->
    </el-drawer>
  </template>
  
  <script lang="ts" setup>
  import { ref, reactive, onMounted } from 'vue'
  import { rolesApi } from '@/api';
  import { dayjs, ElMessageBox, ElMessage, rowContextKey } from 'element-plus'
  import { useRouter } from 'vue-router'
  import ShelfTree from '@/components/ShelfTree.vue'
  const formData = reactive({
    name: '',
  })
  const drawer = ref(false)
  const pageData = reactive({
    total: 0,
    pageSize: 5,
    pageNum: 1
  
  })
  const router = useRouter()
  const tableData = ref([])
  const tableData2 = ref([])
  const edit = (row: any) => {
    rolesApi.select.call({ ioId: row.id }).then(res => {
      tableData2.value = res
      drawer.value = true
    })
  }
  const pageChange = (pageNum: number) => {
    pageData.pageNum = pageNum
    callApi()
  }
  
  const callApi = () => {
    let params = {
      pageNum: pageData.pageNum,
      pageSize: pageData.pageSize,
      name: formData.name == "" ? undefined : formData.name,
  
    }
    rolesApi.select.call(params).then(res => {
  
      pageData.total = res.count
      tableData.value = res.items
      console.log(res)
    })
  }

  
  onMounted(() => {
    callApi()
  
  })
  
  const onSubmit = () => {
    callApi()
  }
  </script>